/*	Nama file		: main.c
	Deskripsi		: Program utama untuk program calender
	Nama pembuat	: Karina Novita Suryani / 23512187
	Hari / Tanggal	: Selasa, 2 Oktober 2012
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Command/command.h"

#define MAX_COMMAND 10

int main(){
	/*Kamus Lokal*/
	
	/*Deklarasi Variabel*/
	int i;
	char* command; //inputan user dalam bentuk string
	
	char** tokenCommand; //array of command
	int countCommand; //jumlah command
	
	ListCal calender;
	
	/* Inisialisasi*/
	mainState = INIT;

	command = (char*) malloc (MAX_STRING * sizeof(char));
	tokenCommand = (char **) malloc (MAX_COMMAND * sizeof (char*));
	
	for (i = 0; i<MAX_COMMAND; i++){
		tokenCommand[i] = (char*) malloc (MAX_STRING * sizeof (char));
	}

	/*Algoritma Main*/
	printf("\nMenu:\n");
	printf("create\n");
	printf("load <nama file>\n");
	printf("<viewall/view> <N> <first/last>\n");
	printf("add\n");
	printf("delete <no event>\n");
	printf("edit <no event>\n");
	printf("save <nama file tanpa spasi>\n");
	printf("quit\n");
	do{
		printf("\n>>");
		scanf(" %[^\n]s",command);
		
		parseCommand(command," ",tokenCommand,&countCommand);
		
		executeCommand(&calender,tokenCommand,countCommand);
		
	} while (mainState != QUIT);
	
	/*Dealokasi command dan tokenCommand*/
	free (command);
	for (i = 0; i<MAX_COMMAND; i++){
		free(tokenCommand[i]);
	}
	free(tokenCommand);
	
	return 0;
}

